package com.edee.bigday.search.controller;

import com.edee.bigday.search.service.CommoditySaveService;
import com.edee.common.exception.BizCodeEnume;
import com.edee.common.to.es.SkuEsModel;
import com.edee.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequestMapping("/search/save")
@RestController
public class ElasticSaveConctroller {
    @Autowired
    CommoditySaveService commoditySaveService;

    //上架商品：
    @PostMapping("/commodity")
    public R commodityStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {
        boolean b = false;
        try {
            b = commoditySaveService.commodityStatusUp(skuEsModels);
        } catch (Exception e) {
            log.error("ElasticSaveConctroller商品上架错误：{}", e);
            return R.error(BizCodeEnume.COMMODITY_UP_EXCEPTION.getCode(), BizCodeEnume.COMMODITY_UP_EXCEPTION.getMsg());
        }
        if (b) {
            //原来判断相反了，2021.2.14 23:30互换结论，by edee。
            return R.error(BizCodeEnume.COMMODITY_UP_EXCEPTION.getCode(), BizCodeEnume.COMMODITY_UP_EXCEPTION.getMsg());
        } else {
            return R.ok();
        }
    }
}
